package weak_20241227_29.io;

import java.io.*;

/**
 * @author zdl
 * @date 2024/12/28
 */
public class Demo11 {
    public static void main(String[] args) throws IOException {
        //11. 编写一个Java程序，读取用户桌面上的"example.txt"文件，将文件中的所有"oldString"替换为"newString"，并将结果保存到"example_replaced.txt"文件中。
        BufferedReader br = new BufferedReader(new FileReader("D:/test/old.txt"));
        BufferedWriter bw = new BufferedWriter(new FileWriter("D:/test/new.txt"));
        String len;
        while ((len = br.readLine())!=null){
            len = len.replace("oldString", "newString");
            bw.write(len);
            bw.newLine();
        }
        bw.close();
        br.close();
    }
}
